package cn.tanglong.shopcart.service.impl;

import cn.tanglong.basic.exception.MyException;
import cn.tanglong.pet.domain.Pet;
import cn.tanglong.pet.mapper.PetDetailMapper;
import cn.tanglong.pet.mapper.PetMapper;
import cn.tanglong.shopcart.Dto.ShopCartDto;
import cn.tanglong.shopcart.domain.ShopCart;
import cn.tanglong.shopcart.mapper.ShopCartMapper;
import cn.tanglong.shopcart.service.IShopCartService;
import cn.tanglong.user.domain.Logininfo;
import cn.tanglong.user.mapper.LogininfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.awt.*;
import java.util.List;

@Service
@Transactional
public class ShopCartServiceImpl implements IShopCartService {

    @Autowired
    private PetMapper petMapper;

    @Autowired
    private PetDetailMapper petDetailMapper;

    @Autowired
    private ShopCartMapper shopCartMapper;

    @Autowired
    private LogininfoMapper logininfoMapper;

    // 更改宠物删除状态
    @Override
    public ShopCart deleteState(ShopCart shopCart) {
        // 校验宠物信息
        if (StringUtils.isEmpty(shopCart)){
            throw new MyException("请选择要删除的订单");
        }

        // 判断宠物状态
        Pet petState = petMapper.selectByIdAndState(shopCart.getPet_id(), Pet.STATE_ONLINE);
        if (petState==null){
            throw new MyException("当前宠物出现异常");
        }
        // 查询宠物所有数据
        Pet pet = shopCartMapper.selectPet(shopCart.getPet_id());
        // 更改宠物删除状态
        shopCartMapper.updateDeleteState(shopCart);
        // 保存
        return null;
    }
}
